<template>
  <div class="boxcard">
    <div class="card" :class="{ selected: isSelected }" @click="handleClick">
      <div class="card-content">
        <h3>{{ title }}</h3>
        <p>状态: 
          <span :class="{ green: status === '空闲', red: status === '忙碌' }"></span>
          {{ status }}
        </p>
        <p>排队人数: {{ queueCount }}人</p>
      </div>
      <div class="checkbox">
        <input type="checkbox" :checked="isSelected" readonly />
      </div>
    </div>
  </div>
  </template>
  
  <script lang="ts" setup>
  import { ref, watch } from 'vue';
  const props = defineProps({
    title: {
        type: String,
        required: true
      },
      status: {
        type: String,
        required: true
      },
      queueCount: {
        type: Number,
        required: true
      },
      modelValue: {
        type: String,
        required: true
      },
      value: {
        type: String,
        required: true
      }
  })
  const emit = defineEmits(['update:modelValue'])
  // eslint-disable-next-line vue/no-setup-props-destructure
  const isSelected = ref<boolean>(props.modelValue === props.value)
    watch(() => props.modelValue, (newValue) => {
        isSelected.value = newValue === props.value;
      });
  
      const handleClick = () => {
        if (!isSelected.value) {
          emit('update:modelValue', props.value);
        }
      };
  </script>
  
  <style scoped>
  .boxcard {
    display: inline-block;
  }
  .card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border: 1px solid #ccc;
    border-radius: 5px;
    cursor: pointer;
    width: 200px;
    transition: background-color 0.3s;
    height: 120px;
    box-sizing: border-box;
    margin-right: 20px;
    margin-bottom: 10px;
  }
  
  .card.selected {
    background-color: lightblue;
  }
  
  .card-content {
    /* flex-grow: 1; */
  }
  
  .checkbox {
    display: flex;
    align-items: center;
  }
  
  .green {
    display: inline-block;
    width: 10px;
    height: 10px;
    background-color: green;
    border-radius: 50%;
    margin-right: 5px;
  }
  
  .red {
    display: inline-block;
    width: 10px;
    height: 10px;
    background-color: red;
    border-radius: 50%;
    margin-right: 5px;
  }
  input {
    width: 30px;
    height: 30px;
  }
  </style>